package com.com.zs21cp.ToolBean;

import com.com.zs21cp.ToolBean.Event;
import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Calendar;
import java.util.Random;

/**
 * @program: flink
 * @description: 、
 * @author: Arctic
 * @create: 2024-03-13 21:10
 */
public class ClickSource implements SourceFunction<Event> {
    private Boolean running =true;

    @Override
    public void run(SourceContext<Event> ctx) throws Exception {
        Random random=new Random();
        String[] users={"Alice","Bob","Carry","Mary","Jack"};
        String[] usrls={"./home","./cart","./fav","/prod?id=100","./prod?id=200"};
        while (running){
            ctx.collect(new Event(
                    users[random.nextInt(users.length)],
                    usrls[random.nextInt(usrls.length)],
                    Calendar.getInstance().getTimeInMillis()
            ));
            Thread.sleep(1000);
        }
    }

    @Override
    public void cancel() {
        running=false;
    }
}